package com.pfzy.ui.activity.nest_recycler.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.pfzy.ui.R
import com.pfzy.ui.activity.nest_recycler.bean.MainTabBean

/**
 * 选项卡
 */
class TabAdapter : BaseQuickAdapter<MainTabBean, BaseViewHolder>(R.layout.item_nest_recycler_tab) {
    override fun convert(holder: BaseViewHolder, item: MainTabBean) {
        val text = if (item.isSelected) "${item.text}\n选中" else item.text
        holder.setText(R.id.txt, text)
    }

    fun setSelectAt(index: Int) {
        data.forEach { it.isSelected = false }
        data[index].isSelected = true
        setList(data)
    }
}